package growTree;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Random;

import javax.swing.Timer;

import tree.Tree;
import tree.Vector2d;


public class GrowSimulation extends Observable{
	private Timer timer;
	private Random random;
	
	private GrowTree tree;
	
	public GrowSimulation(){
		random = new Random();
		
		tree = new GrowTree(new Vector2d(400,400),new Vector2d(0,-1));
		timer = new Timer(10, new TimeListener());
		timer.start();
	}
	
	public GrowTree getTree(){
		return tree;
	}
	
	public void step(){
		
		tree.step(new Vector2d(400,900));
		tree.energize(Math.random()*2);
		setChanged();
		notifyObservers();
	}
	
	private class TimeListener implements ActionListener {

		public void actionPerformed(ActionEvent arg0) {
			step();
		}

	}
}
